package com.zhiche.lisa.mdm.controller.outer;

import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.mdm.dao.model.LicenseType;
import com.zhiche.lisa.mdm.dao.model.bo.LicenseTypeBO;
import com.zhiche.lisa.mdm.service.ILicenseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/licenseType")
@Api(value = "/licenseType", description = "证照类型接口",tags={"证照类型接口"})
public class OutLicenseTypeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OutLicenseTypeController.class);

    @Autowired
    private ILicenseTypeService licenseTypeService;

    @GetMapping(value = "/getLicenTypeBySubjectType")
    @ApiOperation(value = "根据主体获取证照类型", notes = "根据主体获取证照类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<LicenseType>> getLicenseTypeBySujectType(String subjectType) {
        LOGGER.info("LicenseTypeController.getLicenseType（根据主体获取证照类型） params : {} ", subjectType);
        RestfulResponse<List<LicenseType>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),CommonEnum.SUCCESS.getText(),null);
        try {
            List<LicenseType> licenseTypes = licenseTypeService.getLicenseTypesBySujectType(subjectType);
            result.setData(licenseTypes);
        } catch (BaseException e) {
            LOGGER.error("LicenseTypeController.getLicenseType ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("LicenseTypeController.getLicenseType ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getLinceseTypeByTypeCode")
    @ApiOperation(value = "根据类型编码和主体得到证照信息", notes = "根据类型编码和主体得到证照信息", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<LicenseTypeBO> getLinceseTypeByTypeCode(String typeCode, String subjectType ) {
        LOGGER.info("LicenseTypeController.getLinceseTypeByTypeCode（根据主体获取证照类型） params : {} ", subjectType);
        RestfulResponse<LicenseTypeBO> result = new RestfulResponse<>(0,"success",null);
        try {
            LicenseTypeBO licenseTypeBO = licenseTypeService.getLinceseTypeByTypeCode(typeCode,subjectType);
            result.setData(licenseTypeBO);
        } catch (BaseException e) {
            LOGGER.error("LicenseTypeController.getLinceseTypeByTypeCode ERROR... ", e);
            result = new RestfulResponse<>(e.getCode(), e.getMessage(), null);
        }
        return result;
    }
}
